﻿using System;
using System.Collections.Generic;
using System.Text;
using Stauffware.Common.Core;
using NUnit.Framework;

namespace UnitTests.Core
{
	class PrefixDictionary_Tests
	{
		private readonly PrefixDictionary<int> DictUnderTest = new PrefixDictionary<int>(true);

		public PrefixDictionary_Tests ( )
		{
			this.DictUnderTest.Add("foo", 1);
			this.DictUnderTest.Add("foobar", 2);
			this.DictUnderTest.Add("foobaz", 3);
			this.DictUnderTest.Add("xyzzy", 42);
			this.DictUnderTest.Add("this", 11);
			this.DictUnderTest.Add("that", 12);
		}

		[TestCase("foo",	 1, PrefixMatch.Complete)]
		[TestCase("foobar",  2, PrefixMatch.Complete)]
		[TestCase("foobaz",  3, PrefixMatch.Complete)]
		[TestCase("xyzzy",	42, PrefixMatch.Complete)]
		[TestCase("this",	11, PrefixMatch.Complete)]
		[TestCase("that",	12, PrefixMatch.Complete)]
		[TestCase("blrgl",	 0, PrefixMatch.None)]
		[TestCase("fooo",	 0, PrefixMatch.None)]
		[TestCase("fo",		 0, PrefixMatch.Ambiguous)]
		[TestCase("fooba",	 0, PrefixMatch.Ambiguous)]
		[TestCase("t",		 0, PrefixMatch.Ambiguous)]
		[TestCase("th",		 0, PrefixMatch.Ambiguous)]
		[TestCase("thi",	11, PrefixMatch.Partial)]
		[TestCase("tha",	12, PrefixMatch.Partial)]
		public void Lookup (string name, int expectedValue, PrefixMatch expectedMatch)
		{
			int actualValue;
			PrefixMatch actualMatch = this.DictUnderTest.Lookup(name, out actualValue);
			NUnit.Framework.Assert.AreEqual(expectedMatch, actualMatch, "PrefixMatch");
			if (actualMatch == PrefixMatch.Complete || actualMatch == PrefixMatch.Partial)
				NUnit.Framework.Assert.AreEqual(expectedValue, actualValue, "value");
		}

	}
}
